<template>
  <div>
    <div class="box">
      <div class="science_list">
        <el-table
          :data="
            scenicList.slice(
              (currentPage - 1) * pageSize,
              currentPage * pageSize
            )
          "
          v-loading="loading"
          style="width: 100%"
        >
          <el-table-column label="ID" width="100" fixed>
            <template #default="scope">
              <div style="display: flex; align-items: center">
                <span>{{ scope.row.id }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="交易名称" width="200" fixed>
            <template #default="scope">
              <div style="display: flex; align-items: center">
                <span>{{ scope.row.title }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="交易金额" width="180">
            <template #default="scope">
              <div style="display: flex; align-items: center">
                <span>{{ scope.row.money }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="用户" width="200">
            <template #default="scope">
              <div style="display: flex; align-items: center">
                <span>{{ scope.row.name }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="电话" width="200">
            <template #default="scope">
              <div style="display: flex; align-items: center">
                <span>{{ scope.row.tel }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="状态">
            <template #default="scope">
              <div style="display: flex; align-items: center">
                <span>{{ scope.row.status == 0 ? "否" : "是" }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="交易时间" width="180">
            <template #default="scope">
              <div style="display: flex; align-items: center">
                <span>{{ scope.row.createtime }}</span>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="paging">
        <el-pagination
          :align="center"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[1, 5, 10, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="scenicList.length"
        />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import "@wangeditor/editor/dist/css/style.css"; // 引入 css

import { onBeforeUnmount, ref, shallowRef, onMounted } from "vue";
import { Editor, Toolbar } from "@wangeditor/editor-for-vue";
import { reactive } from "vue";
import {
  Plus,
  Delete,
  Search,
  Grid,
  Upload,
  Operation
} from "@element-plus/icons-vue";
// import { CountTo } from "vue3-count-to";
import { userList, recharge } from "@/api/userList";
import { genFileId, ElMessage } from "element-plus";
import type { UploadProps, UploadUserFile } from "element-plus";
import { userlist } from "@/pinia/userlist";
const user = userlist();
console.log(user.userlist);
const currentPage = ref(1);
const pageSize = ref(5);
const scenicList = ref([]);
const loading = ref(true);
//请求列表信息
if (user.tradinglist.length) {
  loading.value = false;
  scenicList.value = user.tradinglist;
} else {
  user.getTradingList().then(res => {
    loading.value = false;
    console.log(res);
    scenicList.value = res;
  });
}
//每页条数改变时触发 选择一页显示多少行
function handleSizeChange(val) {
  console.log(`每页 ${val} 条`);
  currentPage.value = 1;
  pageSize.value = val;
}
//当前页改变时触发 跳转其他页
function handleCurrentChange(val) {
  console.log(`当前页: ${val}`);
  currentPage.value = val;
}
</script>

<style scoped>
.box {
  background-color: white;
  padding: 20px;
}
.button {
  width: 100%;
  display: flex;
  justify-content: space-between;
}
.paging {
  width: 100%;
  text-align: center;
  margin-top: 10px;
}
.el-button--text {
  margin-right: 15px;
}
.el-select {
  width: 300px;
}
.el-input {
  width: 300px;
}
.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>
